package com.walle.userservice;

import java.util.concurrent.locks.Condition;

/**
 * @author zhangjiapeng
 * @Package com.walle.userservice
 * @Description: ${todo}
 * @date 2019/2/13 14:06
 */
public class PrintABC implements Runnable {

    private String code;

    private Object lock;


    public PrintABC(String code,Object lock) {
        this.code = code;
        this.lock = lock;
    }

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        try {
            while (true){
                synchronized (lock){
                    System.out.println(code);
                    Thread.sleep(1000);
                    lock.notifyAll();
                    this.wait();
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
